<template>
    <view class="container">
      
      <!-- 搜索区域 -->
      <view class="search-area">
        <!-- 第一行：标题搜索 -->
        <view class="search-row">
          <view class="search-box">
            <text class="iconfont icon-search search-icon"></text>
            <input 
              type="text" 
              class="search-input" 
              placeholder="请输入岗位名称"  
              confirm-type="search"
              v-model="queryCondition.jobName"
              @confirm="handleSearch"
            />
            <text class="iconfont icon-close clear-icon" v-if="queryCondition.jobName" @tap="clearSearch"></text>
          </view>
          <view class="search-btn" @tap="handleSearch">搜索</view>
          <view class="filter-btn" @tap="showFilterPanel">筛选</view>
        </view>
        
        <!-- 第二行：地区选择 -->
        <view class="location-row">
          <!-- 省份选择器 -->
          <view class="location-item rounded-selector">
            <picker 
              mode="selector" 
              :range="provinceOptions" 
              @change="onProvinceChange" 
              :value="selectedProvinceIndex"
            >
              <view class="picker-item">
                <text class="location-text">{{ provinceOptions[selectedProvinceIndex] === '全部' ? '选择省份' : provinceOptions[selectedProvinceIndex] }}</text>
                <uni-icons type="bottom" size="12" color="#666" class="location-icon"></uni-icons>
              </view>
            </picker>
          </view>
          
          <!-- 城市选择器 -->
          <view class="location-item rounded-selector">
            <picker 
              mode="selector" 
              :range="cityOptions" 
              @change="onCityChange" 
              :value="selectedCityIndex"
              :disabled="!selectedProvince"
            >
              <view class="picker-item" :class="{'disabled': !selectedProvince}">
                <text class="location-text">{{ cityOptions[selectedCityIndex] === '全部' ? '选择城市' : cityOptions[selectedCityIndex] }}</text>
                <uni-icons type="bottom" size="12" color="#666" class="location-icon"></uni-icons>
              </view>
            </picker>
          </view>
          
          <!-- 区县选择器 -->
          <view class="location-item rounded-selector">
            <picker 
              mode="selector" 
              :range="districtOptions" 
              @change="onDistrictChange" 
              :value="selectedDistrictIndex"
              :disabled="!selectedCity"
            >
              <view class="picker-item" :class="{'disabled': !selectedCity}">
                <text class="location-text">{{ districtOptions[selectedDistrictIndex] === '全部' ? '选择区域' : districtOptions[selectedDistrictIndex] }}</text>
                <uni-icons type="bottom" size="12" color="#666" class="location-icon"></uni-icons>
              </view>
            </picker>
          </view>
        </view>
      </view>
  
      <!-- 可滚动区域：岗位列表 -->
      <scroll-view 
        scroll-y 
        class="job-list" 
        @scrolltolower="loadMore"
        refresher-enabled
        :refresher-triggered="isRefreshing"
        @refresherrefresh="onRefresh"
      >
        <view class="job-card" v-for="(item, index) in jobList" :key="index" @tap="goToDetail(item)">
          <view class="job-header">
            <view class="job-title">{{item.jobName}}</view>
            <view class="job-salary">{{item.salary || '面议'}}</view>
          </view>
          <view class="job-company">{{item.companyName}}</view>
          <view class="job-info">
            <text class="job-tag">{{getCompanyTypeText(item.companyType)}}</text>
            <text class="job-tag degree-tag">{{getDegreeText(item.degree)}}</text>
            <text class="job-tag" v-if="item.type !== undefined && item.type !== ''">{{getTypeText(item.type)}}</text>
            <text class="job-tag" v-if="item.isWeave !== undefined && item.isWeave !== ''">{{getYesNoText(item.isWeave) === '是' ? '带编' : '不带编'}}</text>
            <text class="job-tag job-address-tag" v-if="item.jobAddress">
              <text class="job-address-icon iconfont icon-location"></text>
              {{item.jobAddress}}
            </text>
          </view>
          <view class="job-status">
            <view class="job-application-time" v-if="item.startDate || item.endDate">
              <text class="job-time-label">报名时间：</text>
              <text class="job-time-value">{{ item.startDate && item.endDate ? `${item.startDate} ~ ${item.endDate}` : (item.endDate || '暂无') }}</text>
            </view>
            <text :class="['status-tag', getStatusClass(item.status)]">{{getStatusText(item.status)}}</text>
          </view>
        </view>
        
        <!-- 加载更多提示 -->
        <view class="loading-more" v-if="jobList.length > 0">
          <text v-if="isLoading">加载中...</text>
          <text v-else-if="!hasMore">没有更多数据了</text>
        </view>
        
        <!-- 空状态提示 -->
        <view class="empty-state" v-if="jobList.length === 0 && !isLoading">
          <text class="empty-text">暂无相关职位</text>
          <view class="reset-filter-btn" @tap="resetAllFilters">重置筛选条件</view>
        </view>
      </scroll-view>
  
      <!-- 详细筛选面板 -->
      <view class="filter-panel" v-if="showFilter">
        <view class="filter-panel-mask" @tap="hideFilterPanel"></view>
        <view class="filter-panel-content">
          <view class="filter-panel-header">
            <text>详细筛选</text>
            <text class="close-btn" @tap="hideFilterPanel">×</text>
          </view>
          <view class="filter-panel-body">
            <view class="filter-panel-item switch-item">
              <text class="filter-label">不限专业</text>
              <switch :checked="queryCondition.isAllProfession"  @change="handleUnlimitedMajorChange" color="#007aff" />
            </view>
            <view class="filter-panel-item" v-if="!queryCondition.isAllProfession">
              <text class="filter-label">涉及专业</text>
              <view class="filter-input-wrapper">
                <input type="text" placeholder="请输入涉及专业" v-model="queryCondition.aboutProfession" class="filter-input" />
              </view>
            </view>
            <view class="filter-panel-item">
              <text class="filter-label">岗位名称</text>
              <view class="filter-input-wrapper">
                <input type="text" placeholder="请输入岗位名称" v-model="queryCondition.jobName" class="filter-input" />
              </view>
            </view>
            <view class="filter-panel-item">
              <text class="filter-label">公司名称</text>
              <view class="filter-input-wrapper">
                <input type="text" placeholder="请输入公司名称" v-model="queryCondition.companyName" class="filter-input" />
              </view>
            </view>
            <view class="filter-panel-item">
              <text class="filter-label">是否带编</text>
              <picker mode="selector" :range="yesOrNoOptions" range-key="dictLabel" @change="handleWeaveChange" class="filter-picker">
                <view class="filter-picker-text">{{currentWeave.dictLabel || currentWeave.text || '全部'}}</view>
              </picker>
            </view>
            <view class="filter-panel-item">
              <text class="filter-label">招聘类型</text>
              <picker mode="selector" :range="typeOptions" range-key="dictLabel" @change="handleTypeChange" class="filter-picker">
                <view class="filter-picker-text">{{currentType.dictLabel || currentType.text || '全部'}}</view>
              </picker>
            </view>
            <view class="filter-panel-item">
              <text class="filter-label">公司类型</text>
              <picker mode="selector" :range="companyTypeOptions" range-key="dictLabel" @change="handleCompanyTypeChange" class="filter-picker">
                <view class="filter-picker-text">{{currentCompanyType.dictLabel || currentCompanyType.text || '全部'}}</view>
              </picker>
            </view>
            <view class="filter-panel-item">
              <text class="filter-label">报名状态</text>
              <picker mode="selector" :range="statusOptions" range-key="dictLabel" @change="handleStatusChange" class="filter-picker">
                <view class="filter-picker-text">{{currentStatus.dictLabel || currentStatus.text || '全部'}}</view>
              </picker>
            </view>
            
            <view class="filter-panel-item">
              <text class="filter-label">学历要求</text>
              <picker mode="selector" :range="degreeOptions" range-key="dictLabel" @change="handleDegreeChange" class="filter-picker">
                <view class="filter-picker-text">{{currentDegree.dictLabel || currentDegree.text || '全部'}}</view>
              </picker>
            </view>
          </view>
          <view class="filter-panel-footer">
            <button class="reset-btn" @tap="resetFilter">重置</button>
            <button class="confirm-btn" @tap="confirmFilter">确定</button>
          </view>
        </view>
      </view>
    </view>
  </template>
  
  <script>
  import {getRecruitJob} from '@/api/job/recruitJob.js'
import { getRecruitUserDataDetail } from "@/api/recruitUserData/recruitUserData"
import Area from '@/utils/area.js'
import { getDicts } from '@/api/dict/data.js'
import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue'

export default {
  components: {
    uniIcons
  },
  computed: {
    // 公司类型选项
    companyTypeOptions() {
      return [{ dictValue: '', dictLabel: '全部' }].concat(this.companyTypeDict);
    },
    // 学历要求选项
    degreeOptions() {
      return [{ dictValue: '', dictLabel: '不限' }].concat(this.degreeTypeDict);
    },
    // 是否带编选项
    yesOrNoOptions() {
      return [{ dictValue: '', dictLabel: '全部' }].concat(this.yesOrNoDict);
    },
    // 招聘类型选项
    typeOptions() {
      return [{ dictValue: '', dictLabel: '全部' }].concat(this.typeDict);
    },
    // 报名状态选项
    statusOptions() {
      return [{ dictValue: '', dictLabel: '全部' }].concat(this.applyStatusDict);
    }
  },
    data() {
      return {
         // 公司类型字典名称
      companyTypeDictType: 'recruit_company_type',
      // 公司类型字典
      companyTypeDict: [],
      // 学历要求字典名称
      degreeTypeDictType: 'recruit_degree',
      // 学历要求字典
      degreeTypeDict: [],
      // 报名状态字典名称
      applyStatusDictType: 'recruit_notice_status',
      // 报名状态字典
      applyStatusDict: [],
      // 招聘类型字典名称
      typeDictType: 'recruit_type',
      // 招聘类型字典
      typeDict: [],
      // 招聘是否字典名称
      yesOrNoDictType: 'recruit_yes_no',
      // 招聘是否字典
      yesOrNoDict: [],

        queryCondition:{
          aboutProfession:'',
          jobName: '',
          companyName: '',
          companyType:'',
          isWeave:'',
          type:'',
          salaryRange: '',
          jobAddress: '',
          status: '',
          isAllProfession: true,
          degree: '' // 学历要求
        },
        showFilter: false,
        salaryRange: '',
        location: '',
        statusBarHeight: 0,
        jobList: [],
        pageNum: 1,
        pageSize: 10,
        total: 0,
        isLoading: false,
        isRefreshing: false,
        hasMore: true,

        currentStatus: { dictValue: '', dictLabel: '全部' },
        currentWeave: { dictValue: '', dictLabel: '全部' },
        currentType: { dictValue: '', dictLabel: '全部' },
        currentCompanyType: { dictValue: '', dictLabel: '全部' },
        currentDegree: { dictValue: '', dictLabel: '全部' },
        // 地区选择相关
        selectedProvince: '', // 选中的省份
        selectedCity: '', // 选中的城市
        selectedDistrict: '', // 选中的区域
        provinceCode: '', // 省份编码
        cityCode: '', // 城市编码
        districtCode: '', // 区域编码
        // 地区数据
        areaData: [], // 完整的地区数据
        provinceList: [], // 省份列表
        cityList: [], // 城市列表
        districtList: [], // 区域列表
        // 选择器相关
        selectedProvinceIndex: 0,
        selectedCityIndex: 0,
        selectedDistrictIndex: 0,
        provinceOptions: ['全部'],
        cityOptions: ['全部'],
        districtOptions: ['全部']
      }
    },
    onLoad() {
      // 获取状态栏高度，适配不同机型
      const systemInfo = uni.getSystemInfoSync();
      this.statusBarHeight = systemInfo.statusBarHeight;
      
      // 初始化地区数据
      this.initAreaData();
      
      // 加载字典数据
      this.loadDictData();
      
      // 查询用户工作地址
      this.getUser();
      
      // 初始加载数据
      this.fetchJobList();
    },
    methods: {
      // 查询用户工作地址
      getUser() {
          getRecruitUserDataDetail().then(response => {
            const user = response
            if (user.workingCity) {
              this.queryCondition.jobAddress=user.workingCity
            }
          })
        },
  
            // 获取职位列表数据
      async fetchJobList(isRefresh = false) {
        if (this.isLoading) {
          return Promise.resolve();
        }
        
        this.isLoading = true;
        
        if (isRefresh) {
          this.pageNum = 1;
          this.jobList = [];
          this.hasMore = true;
        }
        
        return new Promise((resolve, reject) => {
          try {
            // 构建请求参数
            const params = {
              ...this.queryCondition,
              pageNum: this.pageNum,
              pageSize: this.pageSize
            };
            
            // 调用后端API
            getRecruitJob(params).then(res => {
              if (res.code === 200) {
                const { rows, total } = res;
                
                if (isRefresh) {
                  this.jobList = rows;
                } else {
                  this.jobList = [...this.jobList, ...rows];
                }
                
                // 检查职位数据中的学历字段
                if (rows && rows.length > 0) {
                  console.log('第一个职位数据:', rows[0]);
                  console.log('学历值:', rows[0].degree);
                }
                
                this.total = total;
                // 判断是否还有更多数据
                this.hasMore = this.jobList.length < total;
                
                // 如果当前页数据为空，显示空状态
                if (this.jobList.length === 0) {
                  this.hasMore = false;
                }
                
                resolve();
              } else {
                uni.showToast({
                  title: res.msg || '获取数据失败',
                  icon: 'none'
                });
                reject(new Error(res.msg || '获取数据失败'));
              }
            }).catch(error => {
              console.error('加载数据失败', error);
              uni.showToast({
                title: '网络异常，请稍后重试',
                icon: 'none'
              });
              reject(error);
            }).finally(() => {
              this.isLoading = false;
              this.isRefreshing = false;
            });
          } catch (error) {
            console.error('加载数据失败', error);
            uni.showToast({
              title: '网络异常，请稍后重试',
              icon: 'none'
            });
            this.isLoading = false;
            this.isRefreshing = false;
            reject(error);
          }
        });
      },
      
            // 下拉刷新
      onRefresh() {
        this.isRefreshing = true;
        this.fetchJobList(true).finally(() => {
          this.isRefreshing = false;
        });
      },
      
      // 加载更多
      loadMore() {
        if (!this.hasMore || this.isLoading) {
          return;  
        }
        
        // 如果当前页数据量小于每页数量，说明没有更多数据了
        if (this.jobList.length < this.pageSize) {
          this.hasMore = false;
          return;
        }
        
        this.pageNum++;
        this.fetchJobList();
      },
      
      handleSearchBlur() {
        if (this.queryCondition.aboutProfession) {
          this.handleSearch();
        }
      },
      
      clearSearch() {
        this.queryCondition.jobName = '';
        this.handleSearch();
      },
      
      handleSearch() {
        this.pageNum = 1;
        this.jobList = [];
        this.hasMore = true;
        this.fetchJobList(true);
      },
      
    // 初始化地区数据
    initAreaData() {
      try {
        // 获取地区数据
        this.areaData = Area;
        
        // 初始化省份列表
        this.provinceList = this.areaData.map(province => ({
          code: province.value,
          name: province.label
        }));
        
        // 对省份列表进行重新排序，将云南、贵州、四川、重庆和广西放在前面
        const priorityProvinces = ['云南省', '贵州省', '四川省', '重庆市', '广西壮族自治区'];
        
        // 分离出优先省份和其他省份
        const priorityList = [];
        const otherList = [];
        
        this.provinceList.forEach(province => {
          if (priorityProvinces.includes(province.name)) {
            priorityList.push(province);
          } else {
            otherList.push(province);
          }
        });
        
        // 按照指定的顺序排序优先省份
        priorityList.sort((a, b) => {
          return priorityProvinces.indexOf(a.name) - priorityProvinces.indexOf(b.name);
        });
        
        // 合并优先省份和其他省份
        this.provinceList = [...priorityList, ...otherList];
        
        // 初始化省份选择器选项
        this.provinceOptions = ['全部'].concat(this.provinceList.map(item => item.name));
        
        // 重置城市和区域选择器
        this.cityOptions = ['全部'];
        this.districtOptions = ['全部'];
      } catch (error) {
        console.error('初始化地区数据失败:', error);
        this.provinceList = [];
        this.provinceOptions = ['全部'];
      }
    },
      
      // 省份选择器变化
      onProvinceChange(e) {
        try {
          const index = e.detail.value;
          // 如果选择了第一项（请选择省份），则视为清空选择
          if (index === 0) {
            this.selectedProvinceIndex = 0;
            this.selectedProvince = '';
            this.provinceCode = '';
            this.selectedCity = '';
            this.cityCode = '';
            this.selectedDistrict = '';
            this.districtCode = '';
            this.selectedCityIndex = 0;
            this.selectedDistrictIndex = 0;
            this.cityOptions = ['全部'];
            this.districtOptions = ['全部'];
          } else {
            this.selectedProvinceIndex = index;
            const province = this.provinceList[index - 1]; // 因为选项列表第一项是"全部"
            this.selectedProvince = province.name;
            this.provinceCode = province.code;
            this.selectedCity = '';
            this.cityCode = '';
            this.selectedDistrict = '';
            this.districtCode = '';
            this.selectedCityIndex = 0;
            this.selectedDistrictIndex = 0;
            
            // 加载城市列表
            this.loadCityList();
          }
          
          // 更新查询条件 - 合并省市区
          this.updateAddressQueryCondition();
          
          // 重置页码和列表数据
          this.pageNum = 1;
          this.jobList = [];
          this.hasMore = true;
          
          // 执行搜索
          this.fetchJobList(true);
        } catch (error) {
          console.error('省份选择器变化处理失败:', error);
        }
      },
      
      // 城市选择器变化
      onCityChange(e) {
        try {
          const index = e.detail.value;
          // 如果选择了第一项（请选择城市），则视为清空选择
          if (index === 0) {
            this.selectedCityIndex = 0;
            this.selectedCity = '';
            this.cityCode = '';
            this.selectedDistrict = '';
            this.districtCode = '';
            this.selectedDistrictIndex = 0;
            this.districtOptions = ['全部'];
          } else {
            this.selectedCityIndex = index;
            const city = this.cityList[index - 1]; // 因为选项列表第一项是"全部"
            this.selectedCity = city.name;
            this.cityCode = city.code;
            this.selectedDistrict = '';
            this.districtCode = '';
            this.selectedDistrictIndex = 0;
            
            // 加载区域列表
            this.loadDistrictList();
          }
          
          // 更新查询条件 - 合并省市区
          this.updateAddressQueryCondition();
          
          // 重置页码和列表数据
          this.pageNum = 1;
          this.jobList = [];
          this.hasMore = true;
          
          // 执行搜索
          this.fetchJobList(true);
        } catch (error) {
          console.error('城市选择器变化处理失败:', error);
        }
      },
      
      // 区域选择器变化
      onDistrictChange(e) {
        try {
          const index = e.detail.value;
          // 如果选择了第一项（请选择区域），则视为清空选择
          if (index === 0) {
            this.selectedDistrictIndex = 0;
            this.selectedDistrict = '';
            this.districtCode = '';
          } else {
            this.selectedDistrictIndex = index;
            const district = this.districtList[index - 1]; // 因为选项列表第一项是"全部"
            this.selectedDistrict = district.name;
            this.districtCode = district.code;
          }
          
          // 更新查询条件 - 合并省市区
          this.updateAddressQueryCondition();
          
          // 重置页码和列表数据
          this.pageNum = 1;
          this.jobList = [];
          this.hasMore = true;
          
          // 执行搜索
          this.fetchJobList(true);
        } catch (error) {
          console.error('区域选择器变化处理失败:', error);
        }
      },
      
      // 加载城市列表
      loadCityList() {
        try {
          // 从areaData中查找对应的省份
          const provinceData = this.areaData.find(p => p.value === this.provinceCode);
          if (provinceData && provinceData.children) {
            // 从省份数据中获取城市列表
            this.cityList = provinceData.children.map(city => ({
              code: city.value,
              name: city.label
            }));
            
            // 更新城市选择器选项
            this.cityOptions = ['全部'].concat(this.cityList.map(item => item.name));
          } else {
            this.cityList = [];
            this.cityOptions = ['全部'];
          }
          
          // 重置区域选择器
          this.districtOptions = ['全部'];
        } catch (error) {
          console.error('加载城市数据失败:', error);
          this.cityList = [];
          this.cityOptions = ['全部'];
        }
      },
      
      // 加载区域列表
      loadDistrictList() {
        try {
          // 从areaData中查找对应的省份
          const provinceData = this.areaData.find(p => p.value === this.provinceCode);
          if (provinceData && provinceData.children) {
            // 从省份数据中查找对应的城市
            const cityData = provinceData.children.find(c => c.value === this.cityCode);
            if (cityData && cityData.children) {
              // 从城市数据中获取区域列表
              this.districtList = cityData.children.map(district => ({
                code: district.value,
                name: district.label
              }));
              
              // 更新区域选择器选项
              this.districtOptions = ['全部'].concat(this.districtList.map(item => item.name));
              return;
            }
          }
          this.districtList = [];
          this.districtOptions = ['全部'];
        } catch (error) {
          console.error('加载区域数据失败:', error);
          this.districtList = [];
          this.districtOptions = ['全部'];
        }
      },
      
      // 更新地址查询条件
      updateAddressQueryCondition() {
        // 合并省市区为地址
        let address = '';
        if (this.selectedProvince && this.selectedProvince !== '全部') {
          address = this.selectedProvince;
          if (this.selectedCity && this.selectedCity !== '全部') {
            address += this.selectedCity;
            if (this.selectedDistrict && this.selectedDistrict !== '全部') {
              address += this.selectedDistrict;
            }
          }
        }
        
        // 更新查询条件
        this.queryCondition.jobAddress = address || '';
      },
      
      showFilterPanel() {
        this.showFilter = true;
      },
      
      hideFilterPanel() {
        this.showFilter = false;
      },
      
      handleRegionChange(region) {
        if (!region) return
        
        // 更新查询条件 - 只使用省份代码
        if (region.regionName) {
          this.queryCondition.jobAddress = region.regionName
        }
        
        // 重置分页
        this.pageNum = 1
        this.jobList = []
        
        // 重新加载数据
        this.fetchJobList(true)
      },
      
      resetFilter() {
        
        // 重置查询条件
        this.queryCondition = {
          ...this.queryCondition,
          jobName: '',
          companyName: '',
          companyType: '',
          isWeave: '',
          type: '',
          salaryRange: '',
          isAllProfession: true,
          aboutProfession: ''
        }
        
        // 重置分页
        this.pageNum = 1
        this.jobList = []
        
        // 重新加载数据
        this.loadData()
      },
      
      confirmFilter() {
        this.hideFilterPanel();
        this.handleSearch();
      },
      
      handleTypeChange(e) {
        const index = e.detail.value;
        this.currentType = this.typeOptions[index];
        this.queryCondition.type = this.currentType.dictValue;
      },
      
      handleCompanyTypeChange(e) {
        const index = e.detail.value;
        this.currentCompanyType = this.companyTypeOptions[index];
        this.queryCondition.companyType = this.currentCompanyType.dictValue;
      },
      
      handleWeaveChange(e) {
        const index = e.detail.value;
        this.currentWeave = this.yesOrNoOptions[index];
        this.queryCondition.isWeave = this.currentWeave.dictValue;
      },
      
      // 处理学历选择变化
      handleDegreeChange(e) {
        const index = e.detail.value;
        this.currentDegree = this.degreeOptions[index];
        this.queryCondition.degree = this.currentDegree.dictValue;
      },
  
            // 获取公司类型文本
      getCompanyTypeText(value) {
        if (this.companyTypeDict && this.companyTypeDict.length > 0) {
          const dictItem = this.companyTypeDict.find(item => item.dictValue == value);
          if (dictItem) {
            return dictItem.dictLabel;
          }
        }
        return '未知';
      },

      // 获取学历文本
      getDegreeText(value) {
        console.log('getDegreeText 接收到的值:', value, typeof value);
        if (!value && value !== 0) return '不限';
        const dictValue = String(value);
        console.log('转换后的 dictValue:', dictValue);
        if (this.degreeTypeDict && this.degreeTypeDict.length > 0) {
          console.log('字典数据长度:', this.degreeTypeDict.length);
          const dictItem = this.degreeTypeDict.find(item => item.dictValue === dictValue);
          console.log('找到的字典项:', dictItem);
          if (dictItem) {
            return dictItem.dictLabel;
          }
        }
        return '不限';
      },
  
      // 跳转到详情页
      goToDetail(item) {
        uni.navigateTo({
          url: `/pages/job/detail?jobId=${item.jobId}`
        });
      },
  
            // 处理状态选择变化
      handleStatusChange(e) {
        const index = e.detail.value;
        this.currentStatus = this.statusOptions[index];
        this.queryCondition.status = this.currentStatus.dictValue;
      },

      // 获取状态文本
      getStatusText(value) {
        if (this.applyStatusDict && this.applyStatusDict.length > 0) {
          const dictItem = this.applyStatusDict.find(item => item.dictValue == value);
          if (dictItem) {
            return dictItem.dictLabel;
          }
        }
        
        // 回退到基础状态文本
        const statusMap = {
          3: '即将报名',
          1: '正在报名',
          2: '即将截止',
          4: '结束报名'
        };
        return statusMap[value] || '未知状态';
      },
  
      // 获取招聘类型文本
      getTypeText(value) {
        if (this.typeDict && this.typeDict.length > 0) {
          const dictItem = this.typeDict.find(item => item.dictValue == value);
          if (dictItem) {
            return dictItem.dictLabel;
          }
        }
        return '未知';
      },
      
      // 获取是否带编文本
      getYesNoText(value) {
        if (this.yesOrNoDict && this.yesOrNoDict.length > 0) {
          const dictItem = this.yesOrNoDict.find(item => item.dictValue == value);
          if (dictItem) {
            return dictItem.dictLabel;
          }
        }
        return value == 1 ? '是' : value == 0 ? '否' : '未知';
      },
      
      // 获取状态样式类
      getStatusClass(value) {
        const classMap = {
          3: 'status-upcoming',    // 即将报名
          1: 'status-ongoing',     // 正在报名
          2: 'status-ending',      // 即将截止
          4: 'status-ended'        // 结束报名
        }
        return classMap[value] || ''
      },
  
      // 刷新职位列表
      refreshJobList() {
        this.pageNum = 1;
        this.jobList = [];
        this.hasMore = true;
        this.fetchJobList(true);
      },
  
      // 重置筛选条件
      resetFilter() {
        // 重置查询条件
        this.queryCondition = {
          ...this.queryCondition,
          jobName: '',
          companyName: '',
          companyType: '',
          isWeave: '',
          type: '',
          salaryRange: '',
          isAllProfession: true,
          degree: ''
        }
        
        // 重置选择器的当前值
        this.currentStatus = { dictValue: '', dictLabel: '全部' };
        this.currentWeave = { dictValue: '', dictLabel: '全部' };
        this.currentType = { dictValue: '', dictLabel: '全部' };
        this.currentCompanyType = { dictValue: '', dictLabel: '全部' };
        this.currentDegree = { dictValue: '', dictLabel: '全部' };
        
        // 重置地区选择器
        this.selectedProvinceIndex = 0;
        this.selectedCityIndex = 0;
        this.selectedDistrictIndex = 0;
        this.selectedProvince = '';
        this.selectedCity = '';
        this.selectedDistrict = '';
        this.provinceCode = '';
        this.cityCode = '';
        this.districtCode = '';
        this.cityOptions = ['全部'];
        this.districtOptions = ['全部'];
        
        // 重置分页
        this.pageNum = 1
        this.jobList = []
          
        // 重新加载数据
        this.loadData()
      },
  
            // 重新加载数据
      loadData() {
        this.fetchJobList(true);
      },
      
      // 重置所有筛选条件并重新查询
      resetAllFilters() {
        // 重置查询条件
        this.queryCondition = {
          aboutProfession: '',
          jobName: '',
          companyName: '',
          companyType: '',
          isWeave: '',
          type: '',
          salaryRange: '',
          jobAddress: '',
          status: '',
          isAllProfession: true,
          degree: ''
        };
        
        // 重置筛选面板条件
        this.currentStatus = { dictValue: '', dictLabel: '全部' };
        this.currentWeave = { dictValue: '', dictLabel: '全部' };
        this.currentType = { dictValue: '', dictLabel: '全部' };
        this.currentCompanyType = { dictValue: '', dictLabel: '全部' };
        this.currentDegree = { dictValue: '', dictLabel: '全部' };
        
        // 重置地区选择器
        this.selectedProvinceIndex = 0;
        this.selectedCityIndex = 0;
        this.selectedDistrictIndex = 0;
        this.selectedProvince = '';
        this.selectedCity = '';
        this.selectedDistrict = '';
        this.provinceCode = '';
        this.cityCode = '';
        this.districtCode = '';
        this.cityOptions = ['全部'];
        this.districtOptions = ['全部'];
        
        // 重置页码和列表数据
        this.pageNum = 1;
        this.jobList = [];
        this.hasMore = true;
        
        // 显示加载提示
        uni.showLoading({
          title: '加载中...'
        });
        
        // 执行搜索
        this.fetchJobList(true).then(() => {
          uni.hideLoading();
          
          // 显示重置成功提示
          uni.showToast({
            title: '已重置筛选条件',
            icon: 'none',
            duration: 1500
          });
        }).catch(() => {
          uni.hideLoading();
        });
      },

      handleUnlimitedMajorChange(e) {
        this.queryCondition.isAllProfession = e.detail.value;
        // 如果切换到不限专业，清空专业输入
        if (e.detail.value) {
          this.queryCondition.aboutProfession = '';
        }
      },
      
      // 加载字典数据
      async loadDictData() {
        try {
          // 并行加载所有字典数据
          const [companyTypeRes, degreeTypeRes, applyStatusRes, typeRes, yesOrNoRes] = await Promise.all([
            getDicts(this.companyTypeDictType),
            getDicts(this.degreeTypeDictType),
            getDicts(this.applyStatusDictType),
            getDicts(this.typeDictType),
            getDicts(this.yesOrNoDictType)
          ]);
          
          // 设置字典数据
          if (companyTypeRes.code === 200) {
            this.companyTypeDict = companyTypeRes.data;
          }
         
          if (degreeTypeRes.code === 200) {
            this.degreeTypeDict = degreeTypeRes.data;
            console.log('学历字典数据:', this.degreeTypeDict);
          }
          
          if (applyStatusRes.code === 200) {
            this.applyStatusDict = applyStatusRes.data;
          }
          
          if (typeRes.code === 200) {
            this.typeDict = typeRes.data;
          }
          
          if (yesOrNoRes.code === 200) {
            this.yesOrNoDict = yesOrNoRes.data;
          }
        } catch (error) {
          console.error('加载字典数据失败', error);
        }
      }
    }
  }
  </script>
  
  <style>
  .container {
    padding: 10 20rpx;
    background: #f5f7fa;
    min-height: 100vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100vh;
  }
  
  /* 搜索区域样式 */
.search-area {
  position: fixed;
  top: var(--status-bar-height-10px);
  left: 0;
  right: 0;
  background-color: #fff;
  padding: 16rpx 24rpx;
  z-index: 100;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
  width: 100%;
  min-height: 180rpx;
  display: flex;
  flex-direction: column;
}

/* 地区选择行样式 */
.location-row {
  display: flex;
  justify-content: space-between;
  margin-top: 14rpx;
  padding: 0 6rpx;
}

.location-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f5f7fa;
  height: 64rpx;
  border-radius: 8rpx;
  margin: 0 6rpx;
  padding: 0 8rpx;
  position: relative;
  overflow: visible;
  z-index: 101;
}

.rounded-selector {
  background-color: #f6f7fb;
  border-radius: 30rpx;
  height: 64rpx;
  box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.05);
  padding: 0 15rpx;
}

.location-item:first-child {
  margin-left: 0;
}

.location-item:last-child {
  margin-right: 0;
}

.location-text {
  font-size: 24rpx;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 85%;
  display: block;
  text-align: center;
  padding-right: 20rpx;
}

.location-icon {
  position: absolute;
  right: 16rpx;
  top: 50%;
  transform: translateY(-50%);
}

.picker-item {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10rpx;
  box-sizing: border-box;
  white-space: nowrap;
}

.picker-item.disabled {
  opacity: 0.6;
}

/* 搜索行样式 */
.search-row {
  display: flex;
  align-items: center;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  background-color: #f5f7fa;
  height: 68rpx;
  border-radius: 8rpx;
  padding: 0 16rpx;
  margin-right: 14rpx;
  box-sizing: border-box;
}

.search-icon {
  font-size: 26rpx;
  color: #999;
  margin-right: 8rpx;
}

.search-input {
  flex: 1;
  height: 100%;
  font-size: 28rpx;
  color: #333;
}

.clear-icon {
  font-size: 24rpx;
  color: #999;
  padding: 8rpx;
}

.search-btn {
  width: 100rpx;
  height: 68rpx;
  background-color: #409EFF;
  color: #fff;
  font-size: 28rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8rpx;
  margin-right: 10rpx;
}

.filter-btn {
  width: 90rpx;
  height: 68rpx;
  background-color: #f5f7fa;
  color: #666;
  font-size: 28rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8rpx;
}
  
  /* 岗位列表样式 */
.job-list {
  flex: 1;
  margin-top: calc(var(--status-bar-height) + 150rpx); /* 调整顶部边距，为搜索区域留出空间 */
  height: calc(100vh - var(--status-bar-height) - 240rpx); /* 增加减去的高度，确保能触发底部事件 */
  padding: 10rpx 5rpx;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}
  
  .job-card {
    background: #fff;
    border-radius: 16rpx;
    padding: 15rpx 24rpx;
    margin-bottom: 15rpx;
    box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
  }
  
  .job-card:active {
    transform: scale(0.98);
  }
  
  .job-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12rpx;
    align-items: center;
  }
  
  .job-title {
    font-size: 34rpx;
    font-weight: bold;
    color: #333;
  }
  
  .job-salary {
    font-size: 32rpx;
    color: #ff7043;
    font-weight: bold;
  }
  
  .job-company {
    font-size: 28rpx;
    color: #666;
    margin-bottom: 16rpx;
  }
  
  .job-info {
    display: flex;
    flex-wrap: wrap;
  }
  
  .job-tag {
    background: #f0f2f5;
    color: #666;
    font-size: 24rpx;
    padding: 6rpx 16rpx;
    border-radius: 6rpx;
    margin-right: 16rpx;
    margin-bottom: 8rpx;
  }
  
  .degree-tag {
    background: #e3f2fd;
    color: #1976d2;
  }
  
  .job-address-tag {
    display: flex;
    align-items: center;
    background: #f0f2f5;
    color: #666;
    max-width: 95%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  /* 加载更多提示 */
  .loading-more {
    text-align: center;
    padding: 20rpx 0;
    color: #999;
    font-size: 24rpx;
  }
  
  /* 空状态提示 */
  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 100rpx 0;
  }
  
  .empty-image {
    width: 200rpx;
    height: 200rpx;
    margin-bottom: 20rpx;
  }
  
  .empty-text {
    font-size: 28rpx;
    color: #999;
    margin-bottom: 30rpx;
  }
  
  .reset-filter-btn {
    margin-top: 20rpx;
    padding: 16rpx 40rpx;
    background-color: #409EFF;
    color: #fff;
    font-size: 28rpx;
    border-radius: 40rpx;
    display: inline-block;
  }
  
  /* 筛选面板样式 */
  .filter-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
  }
  
  .filter-panel-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
  }
  
  .filter-panel-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 24rpx 24rpx 0 0;
    padding: 30rpx;
    transform: translateY(0);
    transition: transform 0.3s;
  }
  
  .filter-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30rpx;
    font-size: 32rpx;
    font-weight: bold;
  }
  
  .close-btn {
    font-size: 40rpx;
    color: #999;
    padding: 10rpx;
  }
  
  .filter-panel-body {
    max-height: 60vh;
    overflow-y: auto;
  }
  
  .filter-panel-item {
    margin-bottom: 30rpx;
  }
  
  .filter-label {
    font-size: 28rpx;
    color: #333;
    margin-bottom: 16rpx;
    display: block;
    font-weight: 500;
  }
  
  .filter-picker {
    background: #f5f7fa;
    height: 72rpx;
    border-radius: 8rpx;
    padding: 0 20rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  
  .filter-picker-text {
    font-size: 28rpx;
    color: #333;
    display: flex;
    align-items: center;
  }
  
  .filter-picker-text::after {
    content: "";
    border-top: 12rpx solid #666;
    border-left: 8rpx solid transparent;
    border-right: 8rpx solid transparent;
    margin-left: 16rpx;
    margin-top: 0;
    align-self: center;
  }
  
  .filter-input-wrapper {
    background: #f5f7fa;
    border-radius: 8rpx;
    padding: 0 20rpx;
  }
  
  .filter-input {
    width: 100%;
    height: 72rpx;
    font-size: 28rpx;
    background: transparent;
  }
  
  .filter-panel-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 30rpx;
    padding-top: 30rpx;
    border-top: 1rpx solid #eee;
  }
  
  .reset-btn, .confirm-btn {
    width: 45%;
    height: 80rpx;
    line-height: 80rpx;
    text-align: center;
    border-radius: 40rpx;
    font-size: 28rpx;
  }
  
  .reset-btn {
    background: #f5f7fa;
    color: #666;
  }
  
  .confirm-btn {
    background: #007aff;
    color: #fff;
  }
  
  /* 状态标签样式 */
  /* 地址样式 */
  .job-address {
    display: flex;
    align-items: center;
    margin-top: 16rpx;
    font-size: 26rpx;
    color: #666;
  }
  
  .job-address-icon {
    margin-right: 8rpx;
    font-size: 24rpx;
    color: #999;
    display: inline-flex;
  }
  
  .job-address-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  /* 状态栏样式 */
  .job-status {
    margin-top: 16rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 16rpx;
    border-top: 1rpx solid #f5f5f5;
  }
  
  /* 报名时间样式 */
  .job-application-time {
    font-size: 24rpx;
    color: #666;
    display: flex;
    align-items: center;
  }
  
  .job-time-label {
    color: #999;
    margin-right: 4rpx;
  }
  
  .job-time-value {
    color: #333;
  }
  
  .status-tag {
    font-size: 24rpx;
    padding: 4rpx 16rpx;
    border-radius: 6rpx;
  }
  
  .status-upcoming {
    background: #e3f2fd;
    color: #1976d2;
  }
  
  .status-ongoing {
    background: #e8f5e9;
    color: #2e7d32;
  }
  
  .status-ending {
    background: #fff3e0;
    color: #f57c00;
  }
  
  .status-ended {
    background: #f5f5f5;
    color: #757575;
  }
  
  .switch-item {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  
  </style>
    